package com.sky.controller.admin;

import com.sky.entity.Orders;
import com.sky.result.Result;
import com.sky.service.ReportService;
import com.sky.service.WorkSpaceService;
import com.sky.vo.OrderReportVO;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.vo.TurnoverReportVO;
import com.sky.vo.UserReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * @program: sky-take-out
 * @description:
 * @author: fmp
 * @create: 2023-04-09 15:10
 * @Version 1.0
 **/
@Slf4j
@RestController
@Api(tags = "数据统计相关接口")
@RequestMapping("/admin/report")
public class ReportController {
    //注入工作台服务层接口实现类
    @Resource
    private WorkSpaceService workSpaceService;
    @Resource
    private ReportService reportService;
    @GetMapping("/userStatistics")
    @ApiOperation("用户统计接口")
    public Result userReport(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                             @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        UserReportVO userReportVO =reportService.userReport(begin, end);
        log.info("开始时间：{}，结束时间{}",begin,end);
        return Result.success(userReportVO);
    }
    @GetMapping("/turnoverStatistics")
    @ApiOperation("营业额统计接口")
    public Result turnoverReport(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                             @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        TurnoverReportVO turnoverReportVO = reportService.turnoverReport(Orders.COMPLETED, begin, end);
        return Result.success(turnoverReportVO);
    }
    @GetMapping("/ordersStatistics")
    @ApiOperation("订单统计接口")
    public Result ordersReport(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                             @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
       OrderReportVO orderReportVO = reportService.ordersReport(Orders.COMPLETED, begin, end);
        return Result.success(orderReportVO);
    }
    @GetMapping("/top10")
    @ApiOperation("销量排名接口")
    public Result topReport(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                               @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        SalesTop10ReportVO salesTop10ReportVO = reportService.topReport(Orders.COMPLETED, begin, end);
        return Result.success(salesTop10ReportVO);
    }
    @ApiOperation("导出表格")
    @GetMapping("/export")
    public void export30DBusinessDate(HttpServletResponse httpServletResponse) throws IOException {
        workSpaceService.export30DBusinessDate(httpServletResponse);
    }


}
